#include "overlay.h"

/* char refer, displ, posit, force; */

#define draw_points(h, component)\
{\
  int i;\
  node *nds = h->nodes;\
  bgnpoint();\
  for (i = 0; i < h->numnodes; i++) {\
    v3d((double *)&nds[i].component);\
    if ((i+1) % 256 == 0) {endpoint(); bgnpoint();}\
  }\
  endpoint();\
}


#define draw_ribbon(h, component)\
{\
  int i;\
  node *nds = h->nodes;\
  bgnline();\
  for (i = 0; i < h->numnodes - 2; i++) {\
    v3d((double *)&nds[i].component);\
    if ((i+1) % 255 == 0) {endline(); bgnline(); v3d((double *)&nds[i].component);}\
  }\
  endline();\
  bgnpoint();\
  v3d((double *)&nds[i++].component);	/* south pole */\
  v3d((double *)&nds[i++].component);	/* north pole */\
  endpoint();\
}


#define draw_rectangular_mesh(h, component)\
{\
  int i, u, v, us = h->usize, vs = h->vsize;\
  int south_pole = h->numnodes - 2, north_pole = h->numnodes - 1;\
  node *nds = h->nodes, *p;\
  bgnclosedline();\
  for (i = 0; i < h->numnodes - 2; i++) {\
    v3d((double *)&nds[i].component);\
    if (((i+1) % vs) == 0) {endclosedline(); bgnclosedline();}\
  }\
  endclosedline();\
  for (v = 0; v < vs; v++) {\
    bgnline();\
    v3d((double *)&nds[south_pole].component);\
    for (u = 0, p = nds + v; u < us; u++, p += vs) v3d((double *)&p->component);\
    v3d((double *)&nds[north_pole].component);\
    endline();\
  }\
}




#define draw_elements(h, component)\
{\
   int i, j, k;\
   int numelms = h->numelems;\
   elem *elmi, *elms = h->elems;\
   for (i = 0; i < numelms; i++) {\
     elmi = &elms[i];\
     switch(k = i % 6) {\
            case 0 : color(CYAN);\
                     break;\
            case 1 : color(GREEN);\
                     break;\
            case 2 : color(MAGENTA);\
                     break;\
            case 3 : color(WHITE);\
                     break;\
            case 4 : color(BLUE);\
                     break;\
            case 5 : color(RED);\
                     break;\
 	    }\
      bgnpolygon();\
      for (j = 0; j < elmi->nomnodes; j++) {\
        v3d(&elmi->vertices[j]->component);\
       }\
      endpolygon();\
    }\
}


#define draw_elements_image(h, component)\
{\
   int i, j, k;\
   elem *elmi, *elms = h->elems;\
   for (i = 0; i < h->numelems; i++) {\
     elmi = &elms[i];\
     switch(k = i % 6) {\
            case 0 : color(overlay_color(CYAN));\
                     break;\
            case 1 : color(overlay_color(GREEN));\
                     break;\
            case 2 : color(overlay_color(MAGENTA));\
                     break;\
            case 3 : color(overlay_color(WHITE));\
                     break;\
            case 4 : color(overlay_color(BLUE));\
                     break;\
            case 5 : color(overlay_color(RED));\
                     break;\
 	    }\
      bgnpolygon();\
      for (j = 0; j < elmi->nomnodes; j++) {\
        v3d(&elmi->vertices[j]->component);\
       }\
      endpolygon();\
    }\
}\


#define draw_triangular_mesh(h, component)\
{\
   int l, j, k;\
   int numelms = h->numelems;\
   vector auxpos;\
   node *nds = h->nodes;\
   elem *elmi, *elms = h->elems;\
   linewidth(2);\
   for (l = 0; l < numelms; l++) {\
     elmi = &elms[l];\
     bgnclosedline();\
     for (j = 0; j < elmi->nomnodes; j++) {\
        vminus(elmi->vertices[j]->component,h->translation,auxpos);\
        vscale(1.008,auxpos,auxpos);\
        vplus(auxpos,h->translation,auxpos);\
        v3d((double *)&auxpos);\
     }\
     endclosedline();\
   }\
}\